/*
 * Copyright (c) 2019. Mikes. All rights reserved.
 *
 * You can contact me with sending email to bWlrZXNfMjAxMkAxNjMuY29t for more information!
 */

package com.climber.android.configuration

import android.app.Application
import android.content.Context
import androidx.fragment.app.FragmentManager
import com.climber.android.BuildConfig
import com.climber.android.commonsdk.app.AppEnv
import com.climber.android.commonsdk.api.ApiObserver
import io.ganguo.library.mvp.ui.mvp.base.delegate.AppLifecycles
import io.ganguo.library.mvp.ui.mvp.di.module.GlobalConfigModule
import io.ganguo.library.mvp.ui.mvp.integration.ConfigModule
import io.ganguo.library.mvp.util.CBaseUtils

/**
 * Created by Mikes at 2019-11-04 11:27
 */
class AppEnvironmentConfiguration : ConfigModule {
    override fun priority(): Int = AppEnv.PRORITY_OF_APP

    override fun applyOptions(context: Context, builder: GlobalConfigModule.Builder) {
        if(CBaseUtils.isMainProcess(context)){
            AppEnv.versionInfo = "BuildConfig.VERSION_NAME(${BuildConfig.VERSION_CODE})-${BuildConfig.FLAVOR}"
            AppEnv.DEV_MODE = BuildConfig.DEV_MODE
            AppEnv.API_BASE_URL = BuildConfig.API_BASE_URL
            AppEnv.DATA_PATH = BuildConfig.DATA_PATH
            AppEnv.UMENG_APP_KEY = BuildConfig.UMENG_APP_KEY
            AppEnv.APP_FLAVOR = BuildConfig.FLAVOR

            AppEnv.USER_AGREEMENT_URL = BuildConfig.USER_AGREEMENT_URL
            AppEnv.PRIVACY_AGREEMENT_URL = BuildConfig.PRIVACY_AGREEMENT_URL

            ApiObserver.DEBUG_MODE = BuildConfig.DEV_MODE
        }
    }

    override fun injectAppLifecycle(context: Context, lifecycles: MutableList<AppLifecycles>) {
        lifecycles.add(object : AppLifecycles{
            override fun attachBaseContext(base: Context) {
            }

            override fun onCreate(application: Application) {
            }

            override fun onTerminate(application: Application) {
            }
        })
    }

    override fun injectActivityLifecycle(context: Context, lifecycles: MutableList<Application.ActivityLifecycleCallbacks>) {
    }

    override fun injectFragmentLifecycle(context: Context, lifecycles: MutableList<FragmentManager.FragmentLifecycleCallbacks>) {}
}